﻿<div id="Content-Body" style="min-width:1000px;">
    <div class="toggle">
        <span class="data-fill" resource="Triggers-Table-Paging">共 @Total 条数据</span>

        <button class="item active">所有触发器</button>
    </div>
    <div class="tools">
        <!--<input type="button" class="button right super-search" resource="Triggers-Table" value="高级搜索" />-->

        <form class="filter right" resource="Triggers-Table,Triggers-Table-Paging">
            <input class="left w280 input" type="text" name="[Fuzzy]Name" placeholder="搜索名称..." /><input type="submit" class="right button" value="Q" />
        </form>


        <!--<input type="button" class="tool button refresh" resource="Triggers-Table" value="刷新"/>-->
        <input type="button" class="tool button insert" resource="Triggers-Table" frame="TempTriggerFrame" command="InsertTrigger" value="新增"/>
        <input type="button" class="tool button update" resource="Triggers-Table" frame="TempTriggerFrame" command="UpdateTrigger" value="修改"/>
        <input type="button" class="tool button delete" PrimaryKey="CommandId" resource="Triggers-Table" command="DeleteTrigger" value="删除"/>
    </div>
    <div class="table-box">
        <table class="table" id="Triggers-Table" command="ReadPageTriggers" parameters="Begin:1,End:12,DefaultOrders:'DCommandId'">
            <thead>
                <tr>
                    <td name="selection" style="width:30px;"><input type="checkbox" /></td>
                    <td class="sort" name="CommandId" style="width:30px;">触发器 ID</td>
                    <td class="sort" name="Sign" style="width:80px;" renderer="return Renderers.triggerSign(data.Sign)">触发器标识</td>
                    <td class="sort" name="Name" style="width:80px;">触发器名称</td>
                    <td class="sort" name="Description" style="width:120px;">触发器说明</td>
                </tr>
            </thead>
        </table>
    </div>

    <div id="Triggers-Table-Paging" command="GetTriggersTotal" resource="Triggers-Table"></div>

    <form id="TempTriggerFrame" text="触发器信息" class="frame temp" onsubmit="return app.frameSubmit(this)">
        <div class="top">
            <div class="right">
                <span class="min" title="最小化"></span>
                <span class="max" title="最大化"></span>
                <span class="close" title="关闭"></span>
            </div>
            <span class="title">查看/修改触发器信息</span>
        </div>
        <div class="content" readonly-where="data.Readonly">
            <div class="content">
                <span class="title">基本信息</span>
                <input type="hidden" name="CommandId" />
                <div class="item">
                    <label class="text">触发器名称：</label>
                    <input verify="notNull" class="input w555" type="text" name="Name" placeholder="触发器名称" />
                </div>
                <br />
                <div class="item">
                    <label class="text">触发器类型：</label>
                    <select class="input w280" name="Type">
                        <option value="C#">C#</option>
                        <option value="T-SQL">T-SQL</option>
                        <option value="System">System</option>
                    </select>
                </div>
                <div class="item">
                    <label class="text">优先级：</label>
                    <input verify="notNull" class="input w120" type="text" name="Priority" placeholder="优先级，值越小越优先执行。" value="0" />
                </div>
                <br />
                <div class="item">
                    <label class="text">绑定方式：</label>
                    <input class="radio" name="TriggerSign1" id="SignIdBind" type="radio" value="4" checked="checked" />
                    <label class="label" for="SignIdBind">Id 绑定</label>
                    <input class="radio ml20" name="TriggerSign1" id="SignSignBind" type="radio" value="8" />
                    <label class="label" for="SignSignBind">Sign 绑定</label>
                </div>
                <div class="item">
                    <label class="text">触发器类型：</label>
                    <input class="radio" name="TriggerSign2" id="SignBefore" type="radio" value="1" checked="checked" />
                    <label class="label" for="SignBefore">前置触发</label>
                    <input class="radio ml20" name="TriggerSign2" id="SignAfter" type="radio" value="2" />
                    <label class="label" for="SignAfter">后置触发</label>
                </div>
                <br />
                <div class="item">
                    <label class="text">绑定信息：</label>
                    <input verify="notNull" class="input w555" type="text" name="Bind" placeholder="绑定信息，多个用逗号分开" />
                </div>
                <br />
                <div class="item">
                    <label class="text">触发器说明：</label>
                    <input verify="notNull" class="input w555" type="text" name="Description" placeholder="触发器说明" />
                </div>
            </div>
            <div class="content">
                <span class="title">代码</span>
                <textarea class="fit input textarea" verify="notNull" name="Code" placeholder="限 2000 字符" style="width: auto; border: none; resize: vertical; min-height: 380px;"></textarea>
            </div>
        </div>
        <div class="bottom">
            <input type="submit" class="button" value="保存修改" display-where="!data.Readonly" />
            <input type="button" class="button close" value="返回" />
        </div>
    </form>


    <script>
        $("#TempTriggerFrame").on("process", function (e, Data) {
            var Sign = 0;

            Sign |= parseInt(Data.TriggerSign1);

            var TriggerSign2 = Data.TriggerSign2 ? Data.TriggerSign2 instanceof Array ? Data.TriggerSign2 : [Data.TriggerSign2] : [];

            for (var i = 0; i < TriggerSign2.length; i++) {
                Sign |= parseInt(TriggerSign2[i]);
            }

            Data.Sign = Sign;

            delete Data.TriggerSign1;
            delete Data.TriggerSign2;
        });

        $("#TempTriggerFrame").on("apply", function (e, Data) {
            if (e.currentTarget != e.target) {
                return;
            }

            var Me = $(this);

            var Sign = Data.Sign;

            if ((Sign & 1) != 0) {
                Data.TriggerSign2 = 1;
            } else if ((Sign & 2) != 0) {
                Data.TriggerSign2 = 2;
            }

            if ((Sign & 4) != 0) {
                Data.TriggerSign1 = 4;
                Data.Bind = Data.NamedBind;
            } else if ((Sign & 8) != 0) {
                Data.TriggerSign1 = 8;
            }
        });


        $.extend(window, {
        });

        app.control($("#Triggers-Table"), "table");
        app.control($("#Triggers-Table-Paging"), "paging");
        app.control($("#Content-Body"), "content");
    </script>
</div>